#ifndef __SYS_CONFIG
#define __SYS_CONFIG

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "ohos_init.h"
#include "cmsis_os2.h"

#include "hal_bsp_pcf8574.h"
#include "hal_bsp_ssd1306.h"
#include "hal_bsp_wifi.h"
#include "hal_bsp_nfc.h"
#include "hal_bsp_nfc_to_wifi.h"
#include "oled_show_log.h"
#include "wifi_device.h"
#include "lwip/netifapi.h"
#include "lwip/sockets.h"
#include "lwip/api_shell.h"
#include "hi_uart.h"
#include "hi_io.h"
#include "hi_gpio.h"
#include "cJSON.h"

#include "oled_show.h"
#include "tcp_task.h"
#include "uart_task.h"
#include "control_task.h"
#include "udp_task.h"

#include "mywifi.h"
#include "mynfc.h"
#include "nfcConfigWifi.h"

#define SERVER_PORT     8480
#define LISTEN_BACKLOG  10

#define OLED_BUF_LEN 20

extern bool Flag_Ok_Tcp;
extern bool Flag_Ok_Uart;

//udp_tack.c
extern struct sockaddr_in gloabel_client_addr;

// 小车当前行驶状态
typedef enum {
    DRIVING_STATUS_RUN     = 0x01, // 前进
    DRIVING_STATUS_BACK    = 0x02, // 后退
    DRIVING_STATUS_LEFT    = 0x03, // 左转
    DRIVING_STATUS_RIGHT   = 0x04, // 右转
    DRIVING_STATUS_STOP    = 0x05, // 停止
    DRIVING_STATUS_ON      = 0x06, // 开启电机
    DRIVING_STATUS_OFF     = 0x07, // 关闭电机
    DRIVING_STATUS_L_SPEED = 0x08, // 低速行驶
    DRIVING_STATUS_M_SPEED = 0x09, // 中速行驶
    DRIVING_STATUS_H_SPEED = 0x0a, // 高速行驶
    DRIVING_STATUS_AUTO_TRACK = 0x0b, //自动循迹
} te_driving_status_t;

// 小车当前形式模式
typedef enum {
    DRIVING_MODE_MANUAL     = 0x01, //手动模式
    DRIVING_MODE_AUTO_TRACK = 0x02, //自动循迹
    DRIVING_MODE_DRIVELESS  = 0x03, //无人驾驶
} te_driving_mode_t;

// 蜂鸣器当前状态
typedef enum {
    BEEP_STATUS_ON   = 0x01,//蜂鸣器开启
    BEEP_STATUS_OFF  = 0x02,//蜂鸣器关闭
} te_beep_status_t;

// 三色灯当前状态 （白灯）
typedef enum {
    LED_STATUS_ON   = 0x01,//白灯开启
    LED_STATUS_OFF  = 0x02,//白灯关闭
} te_led_status_t;

// 小车当前所有状态
typedef struct{
    char local_ip_address[20];  //IP地址
    int client_number;          //客户端连接数
    int left_speed;             //左轮转速
    int right_speed;            //右轮转速
    int power;                  //电量
    int distance;               //距离     
    te_driving_status_t driving_state; //行驶状态
    te_driving_mode_t driving_mode;    //行驶模式    
    te_beep_status_t beep_state;       //蜂鸣器状态
    te_led_status_t led_state;         //三色灯状态
}Car_status;



// 上位机当前控制的设备
typedef enum {
    DEVICE_CAR      = 0x01, //控制小车
    DEVICE_BEEP     = 0x02, //控制蜂鸣器
    DEVICE_CAMERA   = 0x03, //控制摄像头（暂无，2024/3/27）
} te_device_t;

// 上位机当前控制指令
typedef enum {
    COMMAND_SET = 0x01, //设置小车状态
    COMMAND_GET = 0x02, //获取小车状态
} te_command_t;

// 回传结果
typedef enum {
    RESPONSE_SUCCESS    = 0x00, //执行成功
    RESPONSE_ANA_FAILED = 0x01, //JSON解析失败
    RESPONSE_UNDEFINE   = 0x02, //指令不识别
    RESPONSE_DATA_MISS  = 0x03, //数据包丢失
    RESPONSE_SET_FAILED = 0x04, //设置属性失败
} te_response_t;

// 上位机当前指令
typedef struct{
    te_device_t device_id;  //控制的设备
    te_command_t command;   //控制指令
    te_driving_mode_t mode_cmd;     //控制运行模式
    te_driving_status_t state_cmd;  //控制运行状态
    te_beep_status_t beep_cmd;      //控制蜂鸣器
    te_led_status_t led_cmd;        //控制三色灯
    te_response_t response;         //回传结果
    int speed;                      //速度
    int flag_cmd_update;            //指令更新
}Cmd_Now;


    extern Car_status globals_car_status; //定义在main.c
    extern Cmd_Now globals_cmd_now;//定义在main.c
    extern osMutexId_t globals_Mutex_ID;
    extern osMutexId_t uart_update_Mutex_ID;


#include "json.h"

#endif

